import { Component, OnInit } from '@angular/core';
import { ProductService, Product } from "../shared/product.service"
import { FormControl, FormGroup } from '@angular/forms';
import { Observable } from 'rxjs'
// import 'rxjs/Rx'
@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {
  private products: Observable<Product[]>
  // private keyword: string
  private myGroup: FormGroup

  private imgUrl = "http://placehold.it/320x150"
  constructor(private productService: ProductService) {
    this.myGroup = new FormGroup({
      titleFilter: new FormControl()
    })
  }

  ngOnInit() {
    this.products = this.productService.getProducts()

    this.productService.searchEvent.subscribe(
      (params) => { return this.products = this.productService.search(params) }
    )

    // this.myGroup.get('titleFilter').valueChanges.subscribe(value => this.keyword = value)
  }

}

